package com.haoze.nurseapp.controller;

import com.haoze.common.response.Result;
import com.haoze.common.response.ResultGenerator;
import com.haoze.nurseapp.model.DrugCollectionEntity;
import com.haoze.nurseapp.model.StaticmedicineRecordEntity;
import com.haoze.nurseapp.service.InpDispensaryService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: Chenchao
 * @CreateTime: 2020-04-14 10:33
 */
@RestController
@RequestMapping("/nurseapp/dispensary")
public class InpDispensaryController {

    @Autowired
    private InpDispensaryService inpDispensaryService;

    @GetMapping("/queryList")
    @ApiOperation(value = "发药批次")
    public Result queryList(@RequestParam String wardId, @RequestParam(required = false) String dateTime, @RequestParam(required = false) String startDate, @RequestParam(required = false) String endDate) {
        return inpDispensaryService.queryList(wardId, dateTime, startDate, endDate);
    }

    @GetMapping("/queryAppList")
    @ApiOperation(value = "发药批次")
    public Result queryAppList(@RequestParam String wardId, @RequestParam(required = false) String dateTime, @RequestParam(required = false) String startDate, @RequestParam(required = false) String endDate) {
        return inpDispensaryService.queryAppList(wardId, dateTime, startDate, endDate);
    }

    @GetMapping("/pushFullStaticCenter")
    @ApiOperation(value = "静配中心发药，补充中间穿插遗漏数据")
    public Result pushFullStaticCenter(@RequestParam String date) {
        return inpDispensaryService.pushFullStaticCenter(date);
    }

    @GetMapping("/docDetailList")
    @ApiOperation(value = "获取发药单据号详情,type（ACCEPTED已收，UNACCEPTED未领，ALL所有，DEFECT缺失）")
    public Result docDetailList(@RequestParam Integer page, @RequestParam Integer pageSize, @RequestParam String docNo, @RequestParam String type) {
        return inpDispensaryService.docDetailList(docNo, type, page, pageSize);
    }

    @GetMapping("/bedList")
    @ApiOperation(value = "药品对应的床号列表")
    public Result bedList(@RequestParam Integer page, @RequestParam Integer pageSize, @RequestParam String docNo, @RequestParam String phamStdCode) {
        return inpDispensaryService.bedList(docNo, phamStdCode, page, pageSize);
    }

    @GetMapping("/bedDetailList")
    @ApiOperation(value = "病人列表和对应药物列表")
    public Result bedDetailList(@RequestParam Integer page, @RequestParam Integer pageSize, @RequestParam String docNo) {
        return inpDispensaryService.bedDetailList(docNo, page, pageSize);
    }

    @GetMapping("/docDefectDetailList")
    @ApiOperation(value = "获取缺失药品记录")
    public Result docDefectDetailList(@RequestParam Integer page, @RequestParam Integer pageSize, @RequestParam String docNo) {
        return inpDispensaryService.docDefectDetailList(docNo, page, pageSize);
    }

    @PostMapping("/lack")
    @ApiOperation(value = "标记药物缺失")
    public Result lackMedical(@RequestBody List<DrugCollectionEntity> list) {
        return inpDispensaryService.lackMedical(list);
    }

    @GetMapping("/queryReason")
    @ApiOperation(value = "获取退药原因列表")
    public Result queryReason() {
        return inpDispensaryService.queryReason();
    }

    //汇总收药和静配收药分割线-------------------------------------------------------------------------

    @GetMapping("/docStaticDetailList")
    @ApiOperation(value = "获取静配药品列表,type(不传未所有，waitToReceive：待领，received：已领，return：退药) ")
    public Result docStaticDetailList(@RequestParam Integer page
            , @RequestParam Integer pageSize
            , @RequestParam String date
            , @RequestParam String wardId
            , @RequestParam(required = false) @ApiParam(name="需要剔除的barcode",value="") String notInbarCodes
            , @RequestParam(required = false) @ApiParam(name="查找单个barCode",value="") String barCode
            , @RequestParam(defaultValue = "",required = false) @ApiParam(name="return：查询退药列表，received：查找已领药列表，waitToReceive：查找待领药列表，默认：不传查询所有药列表",value="") String type
            , @RequestParam(defaultValue = "",required = false) @ApiParam(name="根据床号，住院号，姓名搜索列表",value="") String searchValue) {
        return inpDispensaryService.docStaticDetailList(date, wardId, page, pageSize, notInbarCodes, barCode, type, searchValue);
    }

    @GetMapping("/docAllStaticDetailList")
    @ApiOperation(value = "获取静配药品列表,type(不传未所有，waitToReceive：待领，received：已领，return：退药)")
    public Result docAllStaticDetailList(@RequestParam Integer page
            , @RequestParam Integer pageSize
            , @RequestParam String date
            , @RequestParam String wardId
            , @RequestParam(required = false) @ApiParam(name="需要剔除的barcode",value="") String notInbarCodes
            , @RequestParam(required = false) @ApiParam(name="查找单个barCode",value="") String barCode
            , @RequestParam(defaultValue = "",required = false) @ApiParam(name="return：查询退药列表，received：查找已领药列表，waitToReceive：查找待领药列表，默认：不传查询所有药列表",value="") String type
            , @RequestParam(defaultValue = "",required = false) @ApiParam(name="根据床号，住院号，姓名搜索列表",value="") String searchValue) {
        return inpDispensaryService.docAllStaticDetailList(date, wardId, page, pageSize, notInbarCodes, barCode, type, searchValue);
    }

    @GetMapping("/docStaticDetailNum")
    @ApiOperation(value = "获取静配药品数量列表，返回MAP类，键值对（UNRECEIVED：待领，RECEIVE：已领，RETURN：退药, TOTAL:总量）")
    public Result docStaticDetailNum(@RequestParam String date, @RequestParam String wardId) {
        return inpDispensaryService.docStaticDetailNum(date, wardId);
    }

    @GetMapping("/queryReturnReason")
    @ApiOperation(value = "获取退药原因列表")
    public Result queryReturnReason() {
        return inpDispensaryService.queryReturnReason();
    }

    @PostMapping("/addReturn")
    @ApiOperation(value = "退药")
    public Result addReturn(@RequestBody(required = false) List<StaticmedicineRecordEntity> list) {
        if(CollectionUtils.isEmpty(list)) return ResultGenerator.genOkResult("核对完成");
        return inpDispensaryService.addReturn(list);
    }

    //PC端接口----------------------------------------------------------------------------------

    @GetMapping("/pcDocDetailList")
    @ApiOperation(value = "PC汇总药品")
    public Result pcDocDetailList(@RequestParam String docNo,@RequestParam(required = false) String drugName, @RequestParam String reqId) {
        return inpDispensaryService.pcDocDetailList(docNo,drugName,reqId);
    }

    @GetMapping("/pcReceivedList")
    @ApiOperation(value = "PC收药记录")
    public Result pcReceivedList(@RequestParam String docNo, @RequestParam String drugCode, @RequestParam String reqId) {
        return inpDispensaryService.pcReceivedList(docNo, drugCode, reqId);
    }

    @GetMapping("/pcDefectedList")
    @ApiOperation(value = "PC拒收记录")
    public Result pcDefectedList(@RequestParam String docNo, @RequestParam String drugCode, @RequestParam String reqId) {
        return inpDispensaryService.pcDefectedList(docNo, drugCode, reqId);
    }

    @GetMapping("/pcPatientPersonList")
    @ApiOperation(value = "PC单个药品分病人明细")
    public Result pcPatientPersonList(@RequestParam String docNo, @RequestParam String drugCode, @RequestParam(required = false) String isPrint,
                                      @RequestParam(required = false) String reqId,@RequestParam(required = false) String prescNo) {
        return inpDispensaryService.pcPatientPersonList(docNo, drugCode, isPrint, reqId,prescNo);
    }

    @GetMapping("/pcNotSendInfo")
    @ApiOperation(value = "PC未发药信息")
    public Result pcNotSendInfo(@RequestParam String docNo,@RequestParam(required = false) String patientInfo,@RequestParam(required = false) String orders) {
        return inpDispensaryService.pcNotSendInfo(docNo,patientInfo,orders);
    }

    @GetMapping("/pcPatientDrugList")
    @ApiOperation(value = "PC单个病人分药品明细")
    public Result pcPatientDrugList(@RequestParam String docNo,@RequestParam(required = false) String patientInfo,@RequestParam(required = false) String drugName, @RequestParam String reqId) {
        return inpDispensaryService.pcPatientDrugList(docNo,patientInfo,drugName, reqId);
    }

    @GetMapping("/pcWritePrintSendDrug")
    @ApiOperation(value = "PC记录打印记录")
    public Result pcWritePrintSendDrug(@RequestParam String docNo, @RequestParam String drugCode, @RequestParam String inpatNum) {
        return inpDispensaryService.pcWritePrintSendDrug(docNo, drugCode, inpatNum);
    }
}
